package com.lczc.soa.service;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.lczc.soa.domain.Apply;
import com.lczc.soa.domain.ApplyExample;
import com.lczc.soa.domain.SearchApplyResponse;
import com.lczc.soa.mapper.ApplyMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ApplyServiceImpl implements ApplyService {
    @Autowired
    private ApplyMapper applyMapper;

    @Override
    public SearchApplyResponse findAllApply(Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum,pageSize);
//        List<Apply> applies = applyMapper.selectByExample(new ApplyExample());
        List<Apply> applies = applyMapper.selectAllWith();
//        for (Apply apply : applies){
//            System.out.println(apply.getApplyId());
//        }
        return new SearchApplyResponse(((Page)applies).getTotal(),applies);
    }

    @Override
    public SearchApplyResponse findApplyLikeName(String keywords, Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum,pageSize);
        List<Apply> applies = applyMapper.selectByLikeName(keywords);
        return new SearchApplyResponse(((Page)applies).getTotal(),applies);
    }

    @Override
    public Apply findApplyById(String applyId) {
        return applyMapper.selectByPrimaryKey(applyId);
    }

    @Override
    public int saveApply(Apply apply) {
        return applyMapper.updateByPrimaryKey(apply);
    }

    @Override
    public List<Apply> findApplyByUserId(String id) {
        return applyMapper.selectApplyByUser(id);
    }

    @Override
    public SearchApplyResponse findApplyByUser(String id, Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum,pageSize);
        List<Apply> applies = applyMapper.selectApplyByUser(id);
        return new SearchApplyResponse(((Page)applies).getTotal(),applies);
    }

    @Override
    public SearchApplyResponse findApplyLikeByUser(String keywords, String id, Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum,pageSize);
        List<Apply> applies = applyMapper.selectApplyLikeByUser(keywords,id);
        return new SearchApplyResponse(((Page)applies).getTotal(),applies);
    }

}
